module.exports = {
    CardSpriteType: cc.Enum({
        cstHandCard: 0, //刚打出去的
        cstHandBack: 1, //牌背
        cstHandDown: 2, //放手上的
        cstHandShow: 3, //显示牌( 胡的时候 )
        cstCPG: 4,
        cstCPGBack: 5,
        cstOutCard: 6,
        cstHandGet: 7 //刚抓到手上的牌
    }),

    EatCardType: cc.Enum({
        none: 0, //无
        ectDuizi: 1, //对子
        ectShun: 2, //顺子 
        ectPeng: 3, //碰
        ectGang: 4, //杠
        ectAnGang: 5, //暗杠
        ectGangShow: 6, //显示杠 
        ectFangGang: 7, //放杠
        ectBu: 8, //补
        ectAnBu: 9, //暗补
        ectFangBu: 10, // 放补
        ectSingle: 11
    }),

    STARTHUTYPE: cc.Enum({
        none: 0,
        sixi: 0x001,
        banbanhu: 0x002,
        queyise: 0x004,
        liuliushun: 0x008,
        yizhihua: 0x010, //一枝花
        jintongyunv: 0x020, //金童玉女
        bubugao: 0x040, //步步高
        santong: 0x080, //三同
        midsixi: 0x100, //中途四喜
        midliuliushun: 0x200 //中途六六顺
    }),

    MJAction: cc.Enum({
        none: 0,
        chi: 0x01, //吃
        peng: 0x02, //碰
        bu: 0x04, //偎      自动
        gang: 0x08, //跑     自动 
        hu: 0x10, //提     自动 
        starthu: 0x20, //胡     自动
        midhu: 0x40, //起手胡
        haidi: 0x80 //海底
    }),

    HUTYPE: cc.Enum({
        none: 0,
        xiaohu: 0x0001, //小胡      3提 5坎        （息数x2-13）/3*番数                  
        zimohu: 0x0002, //自模 基础分上再加1    
        pengpenghu: 0x0004, //碰碰
        jiangjianghu: 0x0008, //将将
        qingyise: 0x0010, //清一色
        qiduizi: 0x0020, //7小对
        haohua7dui: 0x0040, //豪7小对
        chaohaohua7dui: 0x0080, //超豪7
        tinghu: 0x0100, //听胡
        qiangganghu: 0x0200, //抢杠
        ganghu: 0x0400, //开杠
        mengqing: 0x0800, //杠上双花
        tianhu: 0x1000, //天胡
        haidihu: 0x2000, //海底胡
        zhuang: 0x4000, //中庄
        quangqiuren: 0x8000 //全球人
    }),


    QuickSortB: function (cards, nCount, nMin, nMax) {
        if (nCount > 0) {
            while (true) {
                var ntMin = nMin;
                var ntMax = nMax;
                var card = cards[(nMin + nMax) >> 1];
                while (true) {
                    while (cards[ntMin] < card) ntMin++;
                    while (cards[ntMax] > card) ntMax--;
                    if (ntMin <= ntMax) {
                        var tmpCard = cards[ntMin];
                        cards[ntMin] = cards[ntMax];
                        cards[ntMax] = tmpCard;
                        ntMin++;
                        ntMax--;
                    }
                    if (ntMin > ntMax) break;
                }
                if (nMin < ntMax) this.QuickSortB(cards, nCount, nMin, ntMax);
                nMin = ntMin;
                if (ntMin >= nMax) break;
            }
        }
    },

    sortCard: function (cards, nCount) {
        for (var i = 0; i < nCount; i++) {
            if (cards[i] == 35)
                cards[i] = -1;
        }

        this.QuickSortB(cards, nCount, 0, nCount - 1);
        for (var i = 0; i < nCount; i++) {
            if (cards[i] == -1)
                cards[i] = 35;
        }
    },

    createCpgItem: function (cpgCards, item) {
        cpgCards[0] = -1;
        cpgCards[1] = -1;
        cpgCards[2] = -1;
        cpgCards[3] = -1;
        switch (item.type) {
            case this.EatCardType.ectDuizi:
                cpgCards[0] = item.card;
                cpgCards[1] = item.card;
                return 2;
            case this.EatCardType.ectShun:
                cpgCards[0] = item.first;
                cpgCards[1] = item.card;
                cpgCards[2] = item.first + 2;
                if (item.card == item.first) {
                    cpgCards[0] = item.first + 1;
                } else if (item.card == item.first + 2) {
                    cpgCards[2] = item.first + 1;
                }
                return 3;
            case this.EatCardType.ectPeng:
                cpgCards[0] = item.card;
                cpgCards[1] = item.card;
                cpgCards[2] = item.card;
                return 3;
            case this.EatCardType.ectGang:
            case this.EatCardType.ectFangGang:
            case this.EatCardType.ectFangBu:
            case this.EatCardType.ectBu:
                cpgCards[0] = item.card;
                cpgCards[1] = item.card;
                cpgCards[2] = item.card;
                cpgCards[3] = item.card;
                return 4;
            case this.EatCardType.ectAnGang:
            case this.EatCardType.ectAnBu:
            case this.EatCardType.ectGangShow:
                cpgCards[0] = 0xf0;
                cpgCards[1] = 0xf0;
                cpgCards[2] = 0xf0;
                cpgCards[3] = item.card;
                return 4;
            case this.EatCardType.ectSingle:
                cpgCards[0] = item.card;
                return 1;
        }
        return 0;
    }
};

// module.exports = MJCommon;